<script setup lang='ts'>
import { useMemberStore } from '@/stores'

// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
// 订单选项
const orderTypes = [
  { type: 4, text: '全部', icon: 'icon-currency' },
  { type: 0, text: '未支付', icon: 'icon-gift' },
  { type: 1, text: '已支付', icon: 'icon-check' },
  { type: 5, text: '已取消', icon: 'icon-gift' },
  { type: 2, text: '已退费', icon: 'icon-comment' },
  { type: 3, text: '已完成', icon: 'icon-gift' },
]
// 常用功能列表
const commonlyList = [
  { type: 0, text: '患者信息', icon: 'auth-filled' },
  { type: 1, text: '检查订单', icon: 'tune-filled' },
  { type: 2, text: '测试结果', icon: 'mail-open-filled' },
]
// 挂号记录
const registrationList = [
  { type: 0, text: '全部', icon: 'icon-currency' },
  { type: 1, text: '待收费', icon: 'icon-gift' },
  { type: 2, text: '待就诊', icon: 'icon-gift' },
  { type: 3, text: '就诊中', icon: 'icon-check' },
  { type: 4, text: '完成', icon: 'icon-comment' },
  { type: 5, text: '已退号', icon: 'icon-gift' },
]
// 获取会员信息
const memberStore = useMemberStore()

// 常用功能点击事件
const commonChange: UniHelper.UniGridOnChange = (e) => {
  let index = e.detail.index
  switch (index) {
    case 0:
      // 跳转到就诊人
      uni.navigateTo({
        url: '/pagesMember/personMedical/personMedical',
      })
      break
    case 1:
      // 跳转到检查订单
      uni.navigateTo({
        url: '/pagesMember/checkOrder/checkOrder',
      })
      break
    case 2:
      // 跳转到健康测试
      uni.navigateTo({
        url: '../health/componets/ResultShow',
      })
      break
  }
}
</script>

<template>
  <scroll-view class='viewport' scroll-y enable-back-to-top>
    <!-- 个人资料 -->
    <view class='profile' :style="{ paddingTop: safeAreaInsets!.top + 'px' }">
      <!-- 情况1：已登录 -->
      <view class='overview' v-if='memberStore.profile'>
        <navigator url='/pagesMember/profile/profile' hover-class='none'>
          <image class='avatar' mode='aspectFill' :src='memberStore.profile?.avatar'></image>
        </navigator>
        <view class='meta'>
          <view class='nickname'> {{ memberStore.profile.name }}</view>
          <navigator class='extra' url='/pagesMember/profile/profile' hover-class='none'>
            <text class='update'>更新头像昵称</text>
          </navigator>
        </view>
      </view>
      <!-- 情况2：未登录 -->
      <view class='overview' v-else>
        <navigator url='/pages/login/login' hover-class='none'>
          <image
            class='avatar gray'
            mode='aspectFill'
            src='https://hos-health.oss-cn-guangzhou.aliyuncs.com/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20231219142955.png'
          >
          </image>
        </navigator>
        <view class='meta'>
          <navigator url='/pages/login/login' hover-class='none' class='nickname'>
            未登录
          </navigator>
          <view class='extra'>
            <text class='tips'>点击登录账号</text>
          </view>
        </view>
      </view>
      <navigator class='settings' url='/pagesMember/settings/settings' hover-class='none'>
        设置
      </navigator>
    </view>
    <!-- 挂号记录 -->
    <view class='registration'>
      <view class='title'> 患者挂号记录</view>
      <view class='section'>
        <!-- 订单 -->
        <navigator
          v-for='item in registrationList'
          :key='item.type'
          :class='item.icon'
          :url='`/pagesOrder/registrationList/registrationList?type=${item.type}`'
          class='navigator'
          hover-class='none'
        >
          {{ item.text }}
        </navigator>
      </view>
    </view>
    <!-- 互联网医院挂号记录 -->
    <view class='orders'>
      <view class='title'>
        患者病例列表
        <navigator class='navigator' url='/pagesOrder/list/list?type=0' hover-class='none'>
          查看全部订单
          <text class='icon-right'></text>
        </navigator>
      </view>
      <view class='section'>
        <!-- 订单 -->
        <navigator
          v-for='item in orderTypes'
          :key='item.type'
          :class='item.icon'
          :url='`/pagesOrder/list/list?type=${item.type}`'
          class='navigator'
          hover-class='none'
        >
          {{ item.text }}
        </navigator>
      </view>
    </view>
    <!--常用功能-->
    <view class='commonTool'>
      <uni-section title='常用功能' type='line' padding>
        <uni-grid
          class='item'
          :column='4'
          :showBorder='false'
          :highlight='true'
          @change='commonChange'
        >
          <uni-grid-item v-for='(item, index) in commonlyList' :index='index' :key='item.type'>
            <view class='grid-item-box' style='background-color: #fff'>
              <uni-icons :type='item.icon' :size='30' color='#777' />
              <view class='text'>{{ item.text }}</view>
            </view>
          </uni-grid-item>
        </uni-grid>
      </uni-section>
    </view>

    <HosNewsList />
  </scroll-view>
</template>

<style lang='scss' scoped>
page {
  height: 100%;
  overflow: hidden;
  background-color: #f7f7f8;
}

.viewport {
  height: 100%;
  background-repeat: no-repeat;
  background-image: url(https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/images/center_bg.png);
  background-size: 100% auto;
}

/* 用户信息 */
.profile {
  margin-top: 20rpx;
  position: relative;

  .overview {
    display: flex;
    height: 120rpx;
    padding: 0 36rpx;
    color: #fff;
  }

  .avatar {
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    background-color: #eee;
  }

  .gray {
    //filter: grayscale(100%);
  }

  .meta {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    line-height: 30rpx;
    padding: 16rpx 0;
    margin-left: 20rpx;
  }

  .nickname {
    max-width: 350rpx;
    margin-bottom: 16rpx;
    font-size: 30rpx;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .extra {
    display: flex;
    font-size: 20rpx;
  }

  .tips {
    font-size: 22rpx;
  }

  .update {
    padding: 3rpx 10rpx 1rpx;
    color: rgba(255, 255, 255, 0.8);
    border: 1rpx solid rgba(255, 255, 255, 0.8);
    margin-right: 10rpx;
    border-radius: 30rpx;
  }

  .settings {
    position: absolute;
    bottom: 0;
    right: 40rpx;
    font-size: 30rpx;
    color: #fff;
  }
}

/*挂号记录*/
.registration {
  position: relative;
  z-index: 99;
  padding: 30rpx;
  margin: 50rpx 20rpx 0;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: inset 0 25rpx 15rpx -5rpx #d8f5e5;

  .title {
    height: 40rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    color: #1e1e1e;
    font-weight: 800;

    .navigator {
      font-size: 24rpx;
      color: #939393;
      float: right;
    }
  }

  .section {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 40rpx 20rpx 10rpx;

    .navigator,
    .contact {
      text-align: center;
      font-size: 24rpx;
      color: #333;

      &::before {
        display: block;
        font-size: 60rpx;
        color: #3ecd80;
        border: none;
      }
    }

    .contact {
      padding: 0;
      margin: 0;
      border: 0;
      background-color: transparent;
      line-height: inherit;
    }
  }
}

/* 我的订单 */
.orders {
  position: relative;
  z-index: 99;
  padding: 30rpx;
  margin: 50rpx 20rpx 0;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: inset 0 25rpx 15rpx -5rpx #7de1ac;

  .title {
    height: 40rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    color: #1e1e1e;
    font-weight: 800;

    .navigator {
      font-size: 24rpx;
      color: #939393;
      float: right;
    }
  }

  .section {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 40rpx 20rpx 10rpx;

    .navigator,
    .contact {
      text-align: center;
      font-size: 24rpx;
      color: #333;

      &::before {
        display: block;
        font-size: 60rpx;
        color: #3ecd80;
        border: none;
      }
    }

    .contact {
      padding: 0;
      margin: 0;
      border: 0;
      background-color: transparent;
      line-height: inherit;
    }
  }
}

/* 常用功能 */
.commonTool {
  margin-top: 20rpx;

  .item {
    text-align: center;

    .grid-item-box {
      height: 60rpx;
    }
  }
}
</style>
